import React, { useRef } from 'react';
import { connect } from 'umi';

import UpdateCancelModal from './UpdateCancelModal';

import { useProcurementMethodManage } from '../common/useProcurementMethodManage';

import { SchemaManage } from '@/components/SchemaComponent';
import { RevokeModal } from '../../Acomponents/RevokeModal';
import { FSBG_STATE_QC } from '../common/Format';
import { ILoadMapTypeAll } from '@/common';
import { getTenantID } from '@/utils';
import { CancelModal } from '@/components/CancelTextModal';

const ProcurementMethodManageView: React.FC<Record<string, any>> = ({ curRes, locationProps }) => {
  const {
    reloadRequest,
    invalidState,
    setInvalidState,
    tableProps,
    searchProps,
    actionList,
    isShowCancel,
    cancelForm,
    submitCancel,
    onChangeCancelModalState,
  } = useProcurementMethodManage({ curRes, locationProps });

  return (
    <div className={'apply-manage'}>
      <SchemaManage ref={useRef()} searchProps={searchProps} actionList={actionList} tableProps={tableProps} />
      {/* 作废弹窗 */}
      {isShowCancel?.isShow && (
        <CancelModal
          checkRows={isShowCancel?.resObj}
          cancelTypeDic={ILoadMapTypeAll.CHANGEPURCHASE_ZFSTATE}
          cancelFormTypeRequired={true}
          cancelFormReasonRequired={true}
          modalTitle={'作废采购变更方式'}
          cancelText={isShowCancel?.resObj?.packName || null}
          cancelRequestUrl={'/purchaseSourceChangeController/cancel'}
          reloadManage={reloadRequest}
          cancelRequestType="PUT"
          cancelRequestBody={{ state: `${getTenantID()}${ILoadMapTypeAll?.PURCHASE_CHANGEWAY}1003` }}
          onClose={() => onChangeCancelModalState({})}
        />
      )}
      {/* 撤销 */}
      {invalidState?.isShow && (
        <RevokeModal
          resObj={invalidState?.resObj}
          revokeRequestUrl={'/purchaseSourceChangeController/invalid'}
          onClose={() => setInvalidState({})}
          reqBody={{ state: FSBG_STATE_QC() }}
          modalTip={
            <div style={{ color: '#000' }}>
              确认是否撤销【<span style={{ color: 'red' }}>{invalidState?.resObj?.packName}</span>】的审核, 撤销后可重新提交！
            </div>
          }
          reloadRequest={reloadRequest}
        />
      )}
    </div>
  );
};

export default connect(({ baseLogin }: Record<string, any>) => ({
  curRes: baseLogin?.permissions,
}))(ProcurementMethodManageView);
